package service

import (
	"fmt"
	"github.com/gin-gonic/gin"
	"monment/pkg"
	"net/http"
	"os"
	"time"
)

func OssUpload(c *gin.Context) {
	file, err := c.FormFile("image")
	if err != nil {
		return
	}
	filename := fmt.Sprintf("/upload/%s/%s", time.Now().Format("20060102"), file.Filename)
	c.SaveUploadedFile(file, filename)
	wd, _ := os.Getwd()
	fileUrl, err := pkg.OssUpload(wd, filename)
	if err != nil {
		return
	}
	c.JSON(http.StatusOK, gin.H{
		"code": 200,
		"msg":  "上传图片成功",
		"data": gin.H{
			"fileUrl": fileUrl,
		},
	})
	return
}
